import React, { useEffect, Component, lazy, Suspense, Fragment } from 'react'
import { useRoutes } from 'react-router-dom'
import routes from './routes'

import { Toast } from 'antd-mobile'

import Loading from '../src/component/loading'
import ErrorBoundary from '../src/views/error'

import { getSession } from '../src/axiosRequest/api2'

//持久化
import { session_cache_key, public_secret_key } from '../src/cache/cacheKey'
import { setCache } from '../src/cache'



function App() {
	const element = useRoutes(routes)

	//[]空数组相当于componentDidMount
	useEffect(() => {
		const obj1 = {
			publicKeyVersion: '1.0.0',
			timestamp: Date.now(),
			signature: '123456789'
		}
		getSession(obj1)
			.then(response => {
				const data = response.data
				console.log('getSession>', data);
				//处理失败
				if (data.code !== 1000) {
					Toast.show({ icon: 'fail', content: data.des })
				}
				
			})
			.catch(error => {
				Toast.show({ icon: 'fail', content: error })
			});

		return () => {
		}
	}, []);

	//渲染组件
	return (
		<ErrorBoundary>
			<Fragment>
				<Suspense fallback={<Loading />}>
					{element}
				</Suspense>
			</Fragment>
		</ErrorBoundary>
	)
}

export default App;
